package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.constant.QuoteException;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckGroupService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkgroup")
public class CheckGroupController {
    @Reference
    private CheckGroupService checkGroupService;

    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        return checkGroupService.findPage(queryPageBean);
    }

    //  查询关系表中检查项的id
    @GetMapping("/findCheckItemIdsByCheckGroupId")
    public Result findCheckItemIdsByCheckGroupId(@RequestParam("id") Integer id) {
        return checkGroupService.findCheckItemIdsByCheckGroupId(id);
    }

    //根据id查询该检查组的具体数据
    @GetMapping("/findById")
    public Result findById(@RequestParam("id") Integer id) {

        return checkGroupService.findById(id);

    }


    //添加检查组
    @PostMapping("/add")
    public Result add(@RequestBody CheckGroup checkGroup,
                      Integer[] checkitemIds) {
        return checkGroupService.add(checkGroup, checkitemIds);

    }

    //删除检查组
    @GetMapping("/delete")
    public Result delete(@RequestParam("id") Integer id) {

        return checkGroupService.deleteById(id);
    }

    //编辑修改检查组
    @PostMapping("/edit")
    public Result edit(@RequestBody CheckGroup checkGroup, Integer[] checkitemIds) {
            return  checkGroupService.edit(checkGroup,checkitemIds);
    }
    //查询所有检查组
    @GetMapping("/findAll")
    public  Result findAll(){
        return  checkGroupService.findAll();
    }
}
